package com.braveman.im.ui.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.braveman.im.R;
import com.braveman.im.bean.ComplainBean;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.ui.adapter.ComplainAdapter;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.vondear.rxtools.RxBarTool;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by 昊昊 on 2017/10/10.
 */

/**
 * 投诉activity
 */
public class ComplainActivity extends BaseActivity {
    private RecyclerView lv;
    private List<ComplainBean> list = new ArrayList<>();
    private ComplainAdapter complainAdapter;
    //private String[] industys = {"拨打电话", "修改信息", "分享名片"};
    private Button btn;
    private EditText editText = null;
    private ComplainBean complainBean;
    private String detailsId;
    private TextView titleContent;

    //判断activity是否是静态页面
    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("投诉").setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.finishActivity(ComplainActivity.this);
            }
        });
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_complain;
    }

    @Override
    protected void initChildView() {
        btn = findViewById(R.id.activity_btn_complain);
        editText = findViewById(R.id.activity_edtxt_content);
        lv = findViewById(R.id.complain_lv);
        lv.setLayoutManager(new LinearLayoutManager(this));
        complainAdapter = new ComplainAdapter(R.layout.item_complain, list);
        lv.setAdapter(complainAdapter);
    }


    @Override
    protected void initChildData() {
        ApiManager.getApi().getComplain("cxgroup").enqueue(new NetCallBack<List<ComplainBean>>() {
            @Override
            protected void onSuccess(Call<List<ComplainBean>> call, Response<List<ComplainBean>> response) {
                if (response != null) {
                    List<ComplainBean> tempList = response.body();
                    list.addAll(tempList);

                    if (complainAdapter != null) {
                        complainAdapter.notifyDataSetChanged();
                    }
                    tempList.get(0).description = editText.getText().toString();
                }
            }
        });

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.activity_btn_complain:
              //  initChildData();
                //  Toast.makeText(this, "editText.getText():" + editText.getText(), Toast.LENGTH_SHORT).show();
                if (editText != null) {
                    ActivityUtils.finishActivity(ComplainActivity.this);
                    Toast.makeText(ComplainActivity.this, "备注不能为空", Toast.LENGTH_SHORT).show();
                } else if (editText == null) {
                    Toast.makeText(ComplainActivity.this, "备注不能为空", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

    @Override
    protected void setChildViewListener() {
        btn.setOnClickListener(this);
        editText.setOnClickListener(this);
    }
}
